/*
Dominique Jannone
Guillaume Marre
Yohan Ojeda
Laurent Schiavon
*/
package Econf_Audio;
/*
 * @(#)AVReceive2.java    1.3 01/03/13
 *
 * Copyright (c) 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies of
 * the software; and ii) Licensee does not utilize the software in a manner
 * which is disparaging to Sun.
 *
 * This software is provided "AS IS," without a warranty of any kind. ALL
 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
 * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
 * LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
 * LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
 * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
 * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
 * OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications; or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */

import java.io.*;
import java.awt.*;
import java.net.*;
import java.awt.event.*;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.media.*;
import javax.media.rtp.*;
import javax.media.rtp.event.*;
import javax.media.rtp.rtcp.*;
import javax.media.protocol.*;
import javax.media.format.AudioFormat;
import javax.media.format.VideoFormat;
import javax.media.Format;
import javax.media.format.FormatChangeEvent;
import javax.media.control.BufferControl;

import model.Constantes;
import model.MainServer;
import model.UserServerDelegate;
/**
 * AVReceive2 to receive RTP transmission using the new RTP API.
 * @param <mgrs>
 */
public class RTPServeur implements ReceiveStreamListener, SessionListener {
	// log
			public static final Logger logger = Logger.getLogger(RTPServeur.class.getName());
	
	// Attributs
		RTPManager mgrs[] = null;
		RTPManager mgrsTransmit[] = null;
//		RTPManager mgrsPart[] = null;
	    boolean dataReceived = false;
	    Object dataSync = new Object();
		private int PortlocalTransmetteur, PortlocalReceveur, numeroDemande, instance, portE;
		private String IPServeur, ttl;
		private Object[][] tabIPetInfoUser, tabUpdateConf;
		private Receveur_Serveur_InFile record;
		private String idConf;

		private int rellePos;
		
	
	// Observateurs
		public Object[][] getTabIPetInfoUser() {return tabIPetInfoUser;}
		public Object[][] getTabUpdateConf() {return tabUpdateConf;}
		public int getNumeroDemande() {return numeroDemande;}
		
	// Mutateur
		public void setTabIPetInfoUser(Object[][] tabIPetInfoUserTMP) {
			int tailleL = tabIPetInfoUserTMP.length;
			int tailleC = tabIPetInfoUserTMP[0].length;
			this.tabIPetInfoUser  = new Object[tailleL][tailleC];
			this.tabIPetInfoUser = tabIPetInfoUserTMP;
		}
		public void setTabUpdateConf(Object[][] TabUpdateConfTMP) {
			int tailleL = TabUpdateConfTMP.length;
			int tailleC = TabUpdateConfTMP[0].length;
			this.tabUpdateConf  = new Object[tailleL][tailleC];
			this.tabUpdateConf = TabUpdateConfTMP;
		}
		public void setNumeroDemande(int numeroDemande) {this.numeroDemande = numeroDemande;}
	
    // Constructeur
    public RTPServeur(String IPServeur, int PortlocalReceveur, int PortlocalTransmetteur, int PortPourEmmision, String idConf) {
		this.PortlocalTransmetteur = PortlocalTransmetteur;
		this.PortlocalReceveur = PortlocalReceveur;
		this.IPServeur = IPServeur;
		this.portE = PortPourEmmision;
		this.idConf = idConf;
		ttl = "1";
		numeroDemande = 1;
		instance = 0;
			if (!initialize()) {
				logger.log(Level.INFO,"Failed to initialize the sessions.");
		        System.exit(-1);
		    }
	}

    // Methode initualize
    protected boolean initialize() {
        try {
        InetAddress ipAddr;
        SessionAddress localAddr = new SessionAddress();
        SessionAddress destAddr;

        mgrs = new RTPManager[1];
//        mgrsPart = new RTPManager[1];
        mgrsTransmit = new RTPManager[1];
        
        // Open the RTP sessions.
        for (int i = 0; i < 1; i++) {
        	logger.log(Level.INFO,"  - Open RTP receveur session for: addr: " + IPServeur + " port: " + PortlocalReceveur + " ttl: " + ttl);
	        // RTPManager Primaire
	        mgrs[i] = (RTPManager) RTPManager.newInstance();
	        mgrs[i].addSessionListener(this);
	        mgrs[i].addReceiveStreamListener(this);
	
	        ipAddr = InetAddress.getByName(IPServeur);
	        destAddr = new SessionAddress( ipAddr, portE);
	        
	        localAddr= new SessionAddress(InetAddress.getLocalHost(), PortlocalReceveur);   
	        mgrs[i].initialize( localAddr);
	
	        // You can try out some other buffer size to see
	        // if you can get better smoothness.
	        BufferControl bc = (BufferControl)mgrs[i].getControl("javax.media.control.BufferControl");
	        if (bc != null)
	            bc.setBufferLength(350);
	        destAddr = new SessionAddress( ipAddr, portE);  
	        mgrs[i].addTarget(destAddr);
        }
        
     // Open the RTP sessionsTransmetteur secondaire for transmetteur.
        for (int i = 0; i < 1; i++) {
//            System.err.println("  - Open RTP transmetteur session for: addr: " + IPServeur + " port: " + PortlocalTransmetteur	 + " ttl: " + ttl);
	
	        mgrsTransmit[i] = (RTPManager) RTPManager.newInstance();
	        //Création d'une SessionAddress 
	        SessionAddress localaddr = new SessionAddress(InetAddress.getLocalHost(),PortlocalTransmetteur);
	        //Initialisation du RTPManager 
	        mgrsTransmit[i].initialize(localaddr);
        }
        } catch (Exception e){
//            System.err.println("Cannot create the RTP Session: " + e.getMessage());
            return false;
        }

    // Wait for data to arrive before moving on.
        long then = System.currentTimeMillis();
        long waitingPeriod = 60000;  // wait for a maximum of 60 secs.

	    try{
	        synchronized (dataSync) {
		        while (!dataReceived && 
		            System.currentTimeMillis() - then < waitingPeriod) {
		            if (!dataReceived){
//		            System.err.println("  - Waiting for RTP data to arrive...");
		            }
//		            else System.err.println("  - Data Arrive ...");
		            dataSync.wait(1000);
		        }
	        }
	    } catch (Exception e) {}

	    if (!dataReceived) {
//	        System.err.println("No RTP data was received.");
	        close();
	        return false;
	    }
	return true;
    }


    /**
     * Close the session managers.
     */
    public void close() {
	    // close the RTP session.
	    for (int i = 0; i < mgrsTransmit.length; i++) {
	        if (mgrsTransmit[i] != null) {
	        	mgrsTransmit[i].removeTargets( "Closing session mgrsTransmit");
	        	mgrsTransmit[i].dispose();
	        	mgrsTransmit = null;
	        }
	    }
	    
	    for (int i = 0; i < mgrs.length; i++) {
	        if (mgrs[i] != null) {
	                mgrs[i].removeTargets("Closing session mgrs");
	                mgrs[i].dispose();
	        mgrs = null;
	        }
	    }
	    // Fin enregistrement
//	    try {
////			record.getSink().stop();
//		} catch (IOException e) {
//			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
//		}
    }

    
    /**
     * SessionListener.
     */
    public synchronized void update(SessionEvent evt) {
    if (evt instanceof NewParticipantEvent) {
        Participant participant = ((NewParticipantEvent)evt).getParticipant();
        logger.log(Level.INFO,"  - A new participant had just joined: " + participant.getCNAME());
        if (instance == 1){
        	try {
         	   ///////////////////////////////
	       	   // Ajouts des ip clients:
        		// ajout les inetAddr (ne pas ajouter l'adresse ip du demandeur)
     	    	 String[] ipParti = participant.getCNAME().split("@"); // Login@PC-NAME
     	    	logger.log(Level.INFO,ipParti[0].toString());
     	    	logger.log(Level.INFO,ipParti[1].toString());
     	    	 // ipParti[1] correspond a l'adresse ip du client ou plutot le nom netBios de la machine
     	    	 // Le fichier etc/hosts doit être a jours ou le DNS.
     	    	 InetAddress ipNet = InetAddress.getByName(ipParti[1].toString());
     	    	logger.log(Level.INFO,">>>>>>>>>>>>IP: "+ipNet.getHostAddress());
     	    	SessionAddress ipSessionEnCours = new SessionAddress(InetAddress.getByName(ipNet.getHostAddress()), portE);
     	    	mgrsTransmit[0].removeTarget(ipSessionEnCours, "Close");
     	    	 
	      	     for (int i = 0; i < tabIPetInfoUser.length; i++) {
	      	    	InetAddress inetAddrClient = InetAddress.getByName(tabIPetInfoUser[i][0].toString());
	      	    	 if(!tabIPetInfoUser[i][0].toString().equals(ipNet.getHostAddress())){
	//      	    		 mgrsTransmit[instance].addTarget(new SessionAddress(inetAddrClient, portE));
	      	    		 mgrsTransmit[0].addTarget(new SessionAddress(inetAddrClient, portE));
	      	    		logger.log(Level.INFO,">>>>>>>>>>>>add Target: "+inetAddrClient.toString());
	      	    	 }
	      		}
	              //////////////////////////////
	 		} catch (Exception e) {
	 			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
	 		}
        }
        
    }
    }

	/**
     * ReceiveStreamListener
     */
    public synchronized void update( ReceiveStreamEvent evt) {
    	
	    RTPManager mgr = (RTPManager)evt.getSource();
	    Participant participant = evt.getParticipant();    // could be null.
	    ReceiveStream stream = evt.getReceiveStream();  // could be null.
	    if (evt instanceof RemotePayloadChangeEvent) {
	    	logger.log(Level.SEVERE,"  - Received an RTP PayloadChangeEvent.");
	    	logger.log(Level.SEVERE,"Sorry, cannot handle payload change.");
	        System.exit(0);
	    }
    
	    else if (evt instanceof NewReceiveStreamEvent) {
	    	logger.log(Level.INFO,"NewReceiveStreamEvent");
	        try {
	        stream = ((NewReceiveStreamEvent)evt).getReceiveStream();
	        DataSource ds = stream.getDataSource();
	        // Find out the formats.
	        RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
		        if (ctl != null){
		        	logger.log(Level.INFO,"  - Recevied new RTP stream: " + ctl.getFormat());
		        } else
		        	logger.log(Level.INFO,"  - Recevied new RTP stream");
		        
		        if (participant == null)
		        	logger.log(Level.INFO,"      The sender of this stream had yet to be identified.");
		        else {
		        	logger.log(Level.INFO,"      The stream comes from: " + participant.getCNAME()); 
		        }
	        
	     // Notify intialize() that a new stream had arrived.
	        synchronized (dataSync) {
	            dataReceived = true;
	            dataSync.notifyAll();
	        }
	        
	        
	        // CLone datasource ds
//	        Object cloneableDataSource = Manager.createCloneableDataSource(ds);
//	        DataSource clonedDataSource = ((SourceCloneable)cloneableDataSource).createClone();
	        
	        
	        // Traitement si c'est le conférencier
		        if (instance == 0){
		        	// Ajout de l'ip du serveur en target
		     	     mgrsTransmit[instance].addTarget(new SessionAddress(InetAddress.getLocalHost(), portE));
		             new Emetteur_serveur(ds, mgrsTransmit, 0);
		             instance = 1;
		             // Enregistrement 
//		             String fileName = "test1"; 
//		             record = new Receveur_InFile_Serveur(clonedDataSource, fileName);
//		             record.start();
		             
		             String fileName = "Enregistrement_Conférence_ID="+idConf;
		            record = new Receveur_Serveur_InFile(portE, fileName);
		     		record.start();
		             
		             
		        } // Traitement pour un nouveau client "parole"
		        else{
		        	logger.log(Level.INFO,">>>> Taitement pour un nouveau client parole: instance = 1");
		        	// Ajout de l'ip du serveur en target
//		    	     mgrsTransmit[instance].addTarget(new SessionAddress(InetAddress.getLocalHost(), portE));
//		        	mgrsTransmit[0].removeTargets( "Closing session mgrsTransmit");
		        	
//		        	mgrsTransmit[0].addTarget(new SessionAddress(InetAddress.getLocalHost(), portE));
//		        	mgrsTransmit[0].addTarget(new SessionAddress(InetAddress.getLocalHost(), portE));
//		    	   // Ajouts des ip clients:
//		    	     for (int i = 0; i < tabIPetInfoUser.length; i++) {
//		    	    	// ajout les inetAddr (ne pas ajouter l'adresse ip du demandeur)
//		    	    	 String[] ipParti = participant.getCNAME().split("@"); // Login@PC-NAME
//		    	    	 System.out.println(ipParti[0].toString());
//		    	    	 System.out.println(ipParti[1].toString());
//		    	    	 InetAddress inetAddrClient = InetAddress.getByName(tabIPetInfoUser[i][0].toString());
//		    	    	 // ipParti[1] correspond a l'adresse ip du client ou plutot le nom netBios de la machine
//		    	    	 // Le fichier etc/hosts doit être a jours ou le DNS.
//		    	    	 InetAddress ipNet = InetAddress.getByName(ipParti[1].toString());
//		    	    	 System.out.println(">>>>>>>>>>>>IP: "+ipNet.getHostAddress());
//		    	    	 if(!tabIPetInfoUser[i][0].toString().equals(ipNet.getHostAddress())){
////		    	    		 mgrsTransmit[instance].addTarget(new SessionAddress(inetAddrClient, portE));
//		    	    		 mgrsTransmit[0].addTarget(new SessionAddress(inetAddrClient, portE));
//		    	    	 }
//					}
//		    	     stream = (ReceiveStream) mgrsPart[1].getReceiveStreams();
//		    	     DataSource dsOrateur = stream.getDataSource();
		    	     new Emetteur_serveur(ds, mgrsTransmit, 0);
		    	     
		        }
	        } catch (Exception e) {
	        	logger.log(Level.SEVERE,"NewReceiveStreamEvent exception " + e.getMessage());
	        	logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
	        return;
	        }
	    }

	    else if (evt instanceof StreamMappedEvent) {
	         if (stream != null && stream.getDataSource() != null) {
	        DataSource ds = stream.getDataSource();
	        // Find out the formats.
	        RTPControl ctl = (RTPControl)ds.getControl("javax.media.rtp.RTPControl");
	        logger.log(Level.INFO,"  - The previously unidentified stream ");
	        if (ctl != null)
	        logger.log(Level.INFO,"      " + ctl.getFormat());
	        logger.log(Level.INFO,"      had now been identified as sent by: " + participant.getCNAME());
	         }
	    }
	    
	    else if (evt instanceof ActiveReceiveStreamEvent) {
	        if (stream != null && stream.getDataSource() != null) {
	       //DataSource ds = stream.getDataSource();
	        	logger.log(Level.INFO,"ActiveReceiveStreamEvent: "+participant.getCNAME());
	        }
	   }
	
	    else if (evt instanceof ByeEvent) {
	    	logger.log(Level.INFO,"  - Got \"bye\" from: " + participant.getCNAME());
	//         PlayerWindow pw = find(stream);
	//         if (pw != null) {
	//        pw.close();
	//        playerWindows.removeElement(pw);
	//         }
	    }
    }

 // Methode 
    static void prUsage() {
    	logger.log(Level.SEVERE,"Usage: AVReceive2 <session> <session> ...");
    	logger.log(Level.SEVERE,"     <session>: <address>/<port>/<ttl>");
	    System.exit(0);
    }
    
    
    // Methode 
    public void addIPdansTabIDetInfoUser(String IP, UserServerDelegate usd, String displayName, String role) throws InvalidSessionAddressException, UnknownHostException, IOException{
    	 // add la référence de la conf et l'ajout dans le tabIdetRTPServer
			if (tabIPetInfoUser != null){
				Object[][] tabIDetInfoUserTMP = new Object[tabIPetInfoUser.length+1][tabIPetInfoUser[0].length];
				for (int i = 0; i < tabIPetInfoUser.length; i++) {
					for (int j = 0; j < tabIPetInfoUser[i].length; j++) {
						tabIDetInfoUserTMP[i][j]=tabIPetInfoUser[i][j];
					}
				}
				// Ajout dans la derniere ligne
				tabIDetInfoUserTMP[tabIPetInfoUser.length][0] = IP;
				tabIDetInfoUserTMP[tabIPetInfoUser.length][1] = usd;
				tabIDetInfoUserTMP[tabIPetInfoUser.length][2] = displayName;
				tabIDetInfoUserTMP[tabIPetInfoUser.length][3] = role;
				setTabIPetInfoUser(tabIDetInfoUserTMP);
			}else{
				Object[][] tabIDetInfoUserTMP = new Object[1][4];
				tabIDetInfoUserTMP[0][0] = IP;
				tabIDetInfoUserTMP[0][1] = usd;
				tabIDetInfoUserTMP[0][2] = displayName;
				tabIDetInfoUserTMP[0][3] = role;
				setTabIPetInfoUser(tabIDetInfoUserTMP);
			}
		// Update les target du mgr
			for (int i = 0; i < mgrsTransmit.length; i++) {
				if(!role.equals(Constantes.ROLE_CONFERENCIER_STRING)){  // ne pas ajouter l'ip du demandeur
					logger.log(Level.INFO,"INFO: Ajout de l'IP "+IP+" dans le mgrsTransmit["+i+"]");
			        mgrsTransmit[i].addTarget(new SessionAddress(InetAddress.getByName(IP), portE));
			        logger.log(Level.INFO,">>>>>>>>>  Parti: "+mgrsTransmit[i].getAllParticipants().toString());
				}
	        }
    }
    
//    public void delTargetUser(UserServerDelegate usd, String displayName, String role) throws InvalidSessionAddressException, UnknownHostException, IOException{
//   	 String IP = null;
//			// add la référence de la conf et l'ajout dans le tabIdetRTPServer
//			if (tabIPetInfoUser != null){
//				Object[][] tabIDetInfoUserTMP = new Object[tabIPetInfoUser.length-1][tabIPetInfoUser[0].length];
//				for (int i = 0; i < tabIPetInfoUser.length; i++) {
//					int rellePos=0;
//					if (!tabIPetInfoUser[i][2].equals(displayName)){
//						for (int j = 0; j < tabIPetInfoUser[i].length; j++) {
//							tabIDetInfoUserTMP[rellePos][j]=tabIPetInfoUser[i][j];
//							rellePos=rellePos++;
//						}
//					}else{
//						// get IP client
//						IP = tabIPetInfoUser[i][0].toString();
//						System.out.println("IP:"+IP);
//					}
//				}
//				setTabIPetInfoUser(tabIDetInfoUserTMP);
//			}
//		// Update les target du mgr
//			for (int i = 0; i < mgrsTransmit.length; i++) {
//				if(!role.equals(Constantes.ROLE_CONFERENCIER_STRING)){  // ne pas ajouter l'ip du demandeur
//					logger.log(Level.INFO,"INFO: Del l'IP "+IP+" dans le mgrsTransmit["+i+"]");
//					InetAddress ipNet = InetAddress.getByName(IP);
//					SessionAddress ipSessionEnCours = new SessionAddress(InetAddress.getByName(ipNet.getHostAddress()), portE);
//					mgrsTransmit[i].removeTarget(ipSessionEnCours, "Bye ...");
//			        logger.log(Level.INFO,">>>>>>>>>  Remove: "+mgrsTransmit[i].getAllParticipants().toString());
//				}
//	        }
//   }gggg
    
    public boolean sendUpdateIHM(){
    	try {
    		if(tabUpdateConf != null){
        		for (int i = 0; i < tabIPetInfoUser.length; i++) {
        			logger.log(Level.INFO,"Run Agent pour IP "+tabIPetInfoUser[i][0].toString());
        			AgentUpdateClient auc = new AgentUpdateClient(tabIPetInfoUser[i][0].toString(), 2222, tabUpdateConf, tabIPetInfoUser[i][3].toString());
        			auc.run();
        			logger.log(Level.INFO,"Fin Agent pour IP "+tabIPetInfoUser[i][0].toString());
    			}
        	}
		} catch (Exception e) {
			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
			return false;
		}
    	return true;
    }
    
    public boolean addParticipantinUpdateIHM(String dn, String roleClient){
    	try {
    		int etatMicro = Constantes.MICRO_NO_OK;
    		
    		if(roleClient.equals(Constantes.ROLE_ORATEUR_STRING)) etatMicro = Constantes.MICRO_OK;
    		if(roleClient.equals(Constantes.ROLE_AUDITEUR_STRING)) etatMicro = Constantes.MICRO_NO_OK;
    		if(roleClient.equals(Constantes.ROLE_ADMINCONF_STRING)) etatMicro = Constantes.MICRO_NO_OK;
    		
    		if (tabUpdateConf != null){
				Object[][] tabUpdateConfTMP = new Object[tabUpdateConf.length+1][tabUpdateConf[0].length];
				for (int i = 0; i < tabUpdateConf.length; i++) {
					for (int j = 0; j < tabUpdateConf[i].length; j++) {
						tabUpdateConfTMP[i][j]=tabUpdateConf[i][j];
					}
				}
				// Ajout dans la derniere ligne
				tabUpdateConfTMP[tabUpdateConf.length][0] = dn;
				tabUpdateConfTMP[tabUpdateConf.length][1] = etatMicro;
				tabUpdateConfTMP[tabUpdateConf.length][2] = "";
				setTabUpdateConf(tabUpdateConfTMP);
			}else{
	    		Object[][] tabUpdateConfTMP = new Object[1][3];
	    		tabUpdateConfTMP[0][0] = dn;
	    		tabUpdateConfTMP[0][1] = etatMicro;
	    		tabUpdateConfTMP[0][2] = "";
				setTabUpdateConf(tabUpdateConfTMP);
			}
		} catch (Exception e) {
			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
			return false;
		}
    	return true;
    }
      
    
    public boolean addConferencierinUpdateIHM(String dn){
    	try {
    		Object[][] tabUpdateConfTMP = new Object[1][3];
    		tabUpdateConfTMP[0][0] = dn;
    		tabUpdateConfTMP[0][1] = Constantes.MICRO_OK;
    		tabUpdateConfTMP[0][2] = "";
			setTabUpdateConf(tabUpdateConfTMP);
        	
		} catch (Exception e) {
			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
			return false;
		}
    	return true;
    }
    
    
    public boolean delParticipantinUpdateIHM(String dn){
    	try {
    		// Supprime l'utilisateur du tapUpdate
    		if (tabUpdateConf != null & tabUpdateConf.length > 1){
				Object[][] tabUpdateConfTMP = new Object[tabUpdateConf.length-1][tabUpdateConf[0].length];
				rellePos=0;
				for (int i = 0; i < tabUpdateConf.length; i++) {
					if (!tabUpdateConf[i][0].equals(dn)){
						for (int k = 0; k < tabUpdateConf[i].length; k++) {
							tabUpdateConfTMP[rellePos][k]=tabUpdateConf[i][k];
							System.out.println("i - k:"+i+"-"+k);
							
						}
						rellePos=rellePos+1;
					}
				}
				setTabUpdateConf(tabUpdateConfTMP); 
    		}
			// Supprime l'utilisateur du tabIpInfosManager	
			if (tabIPetInfoUser != null & tabIPetInfoUser.length > 1){
				Object[][] tabIPetInfoUserTMP = new Object[tabIPetInfoUser.length-1][tabIPetInfoUser[0].length];
				int rellePos=0;
				for (int i = 0; i < tabIPetInfoUser.length; i++) {
					if (!tabIPetInfoUser[i][2].equals(dn)){
						for (int k = 0; k < tabIPetInfoUser[i].length; k++) {
							tabIPetInfoUserTMP[rellePos][k]=tabIPetInfoUser[i][k];
							System.out.println("i - k:"+i+"-"+k);
						}
						rellePos=rellePos+1;
					}
				}
			setTabIPetInfoUser(tabIPetInfoUserTMP);	
			}
		} catch (Exception e) {
			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
			return false;
		}
    	return true;
    }
    
    public boolean modParticipantMicroinUpdateIHM(String dn, int newEtatMicro){
    	try {
    		if (tabUpdateConf != null){
				Object[][] tabUpdateConfTMP = new Object[tabUpdateConf.length][tabUpdateConf[0].length];
				for (int i = 0; i < tabUpdateConf.length; i++) {
					if(tabUpdateConf[i][0].equals(dn)){
						tabUpdateConfTMP[i][0]=tabUpdateConf[i][0];
						tabUpdateConfTMP[i][1]=newEtatMicro;
						tabUpdateConfTMP[i][2]=tabUpdateConf[i][2];
						if (newEtatMicro == Constantes.MICRO_ASK){
							if(!tabUpdateConf[i][1].equals(Constantes.MICRO_ASK)){
								tabUpdateConfTMP[i][2]= " N°"+getNumeroDemande();
								setNumeroDemande(getNumeroDemande()+1);
							}
						}
						if (newEtatMicro == Constantes.MICRO_SPEAK){
							tabUpdateConfTMP[i][2]= " ";
							setNumeroDemande(getNumeroDemande()-1);
						}
					}else{
						for (int j = 0; j < tabUpdateConfTMP.length; j++) {
							// Traitement pour décrémenter les autres si une demande de parole
							if (j == 2 && newEtatMicro == Constantes.MICRO_SPEAK && tabUpdateConf[i][j-1].equals(Constantes.MICRO_ASK)){
								String[] infoNumMicro = tabUpdateConf[i][2].toString().split("°");
								int numAsk = new Integer(infoNumMicro[1]);
									tabUpdateConfTMP[i][j]= " N°"+(numAsk-1);
							}else
							tabUpdateConfTMP[i][j]=tabUpdateConf[i][j];
						}
					}
				}
				setTabUpdateConf(tabUpdateConfTMP);
			}
		} catch (Exception e) {
			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
			return false;
		}
    	return true;
    }
	public void changeTabUpdatePourInformerClientFindeConference() {
		try {
    		Object[][] tabUpdateConfTMP = new Object[1][3];
    		tabUpdateConfTMP[0][0] = "Fin de la conférence";
    		tabUpdateConfTMP[0][1] = Constantes.FIN_CONFERENCE;
    		tabUpdateConfTMP[0][2] = "";
			setTabUpdateConf(tabUpdateConfTMP);
        	
		} catch (Exception e) {
			logger.log(Level.SEVERE,e.getClass() + ": " +  e.getMessage(), e);
		}
		
		
		
	}
  	
    

}// end of AVReceive2 
